/*******************************************************
> Copyright (C) 2024 ==IOT== All rights reserved.
> File Name: alarm.c
> Author: sy
> Website:www.sy.org
> Created Time: 2024年09月23日 星期一 18时00分24秒
***************************************************/
#include "alarm.h"

void Alarm()
{
    char dest[1024] = {0};
    struct manager man;
    memset(&man, 0, sizeof(man));

    output_cJSON_alarm(dest);
}
void output_cJSON_alarm(char *dest)
{
    int ret = 0;
    
    // 创建socket
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd == -1)
    {
        perror("socket error");
        return;
    }
    // 接收
    ret = recv(sockfd, dest, sizeof(dest), 0);
    if (ret == -1)
    {
        perror("recv error");
        close(sockfd);
        return;
    }

    cJSON *json_response = cJSON_Parse(dest);
    if (!json_response)
    {
        printf("Failed to parse JSON response\n");
        free(dest);
        return;
    }
    cJSON *node = cJSON_GetObjectItem(json_response, "directives");
    if (node && node->type == cJSON_String)
    {
        if (strcmp(node->valuestring, "Alarm") == 0)
        {
            node = cJSON_GetObjectItem(json_response, "info");
            if (node && node->type == cJSON_String)
            {
                printf("alarm: %s\n", node->valuestring);
            }
        }
    }

    cJSON_Delete(json_response);
    free(dest);
}
